package com.bamboo.eduorder.controller;


import com.bamboo.commonutils.ResponseEntity;
import com.bamboo.eduorder.entity.Order;
import com.bamboo.eduorder.entity.vo.CreateOrderVo;
import com.bamboo.eduorder.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author jack.wu
 * @since 2020-07-20
 */
@Api(description = "订单管理")
@RestController
@RequestMapping("/eduorder/order")
@CrossOrigin
public class OrderController {

    @Resource
    private OrderService orderService;

    @ApiOperation("根据课程号创建订单")
    @PostMapping
    public ResponseEntity createOrder(@RequestBody CreateOrderVo orderVo) {
        String orderNo = orderService.createOrder(orderVo);
        return ResponseEntity.ok().data("orderNo", orderNo);
    }

    @ApiOperation("查询订单")
    @GetMapping("/{orderNo}")
    public ResponseEntity getOrder(@PathVariable String orderNo) {
        Order order = orderService.getOrderByOrderNo(orderNo);
        return ResponseEntity.ok().data("order", order);
    }

    @ApiOperation("根据课程id和用户id查询订单表中订单状态")
    @GetMapping("isBuyCourse/{courseId}/{memberId}")
    public boolean isBuyCourse(@PathVariable String courseId,@PathVariable String memberId) {
      return  orderService.isBuyCourse(courseId, memberId);
    }

}

